<template>
  <div class="service">
    <van-nav-bar title="申请售后" left-text="返回" left-arrow @click-left="$router.go(-1)" />

    <div style="margin-top: 10px;">
      <van-form @submit="onSubmit">
        <van-field name="type" label="服务类型">
          <template #input>
            <van-radio-group v-model="type" direction="horizontal">
              <van-radio :checked-color="CFG.colorPrimary" name="1">退货</van-radio>
              <van-radio :checked-color="CFG.colorPrimary" name="2">换货</van-radio>
            </van-radio-group>
          </template>
        </van-field>

        <van-field name="quantity" label="提交数量">
          <template #input>
            <van-stepper v-model="quantity" integer min="1" :max="max_quantity" />
          </template>
        </van-field>

        <van-field name="message" v-model="message" rows="3" autosize label="问题描述" type="textarea" maxlength="50" placeholder="请输入问题描述" show-word-limit />

      <van-cell>
				<van-button type="info" block native-type="submit">提交售后</van-button>
			</van-cell>


      </van-form>
    </div>
  </div>
</template>

<script>
  import {
  	Toast
  } from 'vant';
export default {
  data() {
    return {
      message: '',
      type: '1',
      quantity: 1,
      max_quantity: 1
    };
  },
  created() {
      this.max_quantity = this.$route.query.max_quantity
  },
  methods: {
    onSubmit(values) {

      console.log('submit', values);

      this.apiPost('/shop.order/service_create', {
      	order_goods_id: this.$route.query.id,
      	type: values.type,
      	quantity: values.quantity,
      	message: values.message,
      }).then(res => {
        if (res.code == 0) {
        	Toast.success('售后已提交，我们会尽快处理')
        	this.$router.go(-1)
        	//eventBus.$emit('address_update_success', 'ok');
        	//this.backWhere();
        	// this.$router.push("/user/address");
        }else{
          Toast.fail(res.msg)
        }
      });


    }
  },
};
</script>

<style></style>
